import '@/assets/styles/tailwind.css';
import '@/assets/styles/globals.css';
import { DefaultLayout } from '@/layouts';
import { ContentLayout } from '@/layouts';
import type { AppProps } from 'next/app';
import { ConfigProvider } from 'antd';
import { allMenuList, MenuItem } from '@/utils/menu';

export function filterMenuShow(menuList: MenuItem[]) {
  const list: MenuItem[] = [];
  for (const menu of menuList) {
    const children = menu.children ? filterMenuShow(menu.children) : [];
    list.push({
      ...menu,
      children: children.length ? children : undefined,
      label: menu.name,
    });
  }
  return list;
}
const layoutMap = new Map([
  ['content', ContentLayout],
  ['default', DefaultLayout],
]);
export default function App({ Component, pageProps }: AppProps) {
  const headerMenuList: MenuItem[] = filterMenuShow(allMenuList);
  const layout = pageProps.layout || 'content';
  const LayoutComponent = layoutMap.get(layout) || DefaultLayout;
  return (
    <ConfigProvider theme={{ token: { colorPrimary: '#5CAB12' } }}>
      <LayoutComponent menuList={headerMenuList} baseInfo={pageProps.baseInfo}>
        <Component {...pageProps} />
      </LayoutComponent>
    </ConfigProvider>
  );
}
